import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Queue;

import org.junit.Test;

public class MyTest{
    public int[] kWeakestRows(int[][] mat, int k) {
        int left,right,mid;
        ArrayList<Integer> arrayList=new ArrayList<Integer>(mat.length);
        for(int[] arr:mat){
            left=0;
            right=arr.length-1;
            while(left<=right){
                mid=(left+right)/2;
                if(arr[mid]==1){
                    left=mid+1;
                }else{
                    right=mid-1;
                }
            }
            arrayList.add(left);
        }
        Queue<int[]> queue=new PriorityQueue<int[]>(
            mat.length, 
            (first,second)->{
                if(first[1]-second[1]==0){
                    return first[0]-second[0];
                }else{
                    return first[1]-second[1];
                }
            }
        );
        for(int i=0;i<arrayList.size();i++){
            queue.offer(new int[]{i,arrayList.get(i)});
        }
        int[] ans=new int[k];
        for(int i=0;i<k;i++){
            ans[i]=queue.poll()[0];
        }
        return ans;
    }

    public void moveZeroes(int[] nums) {
        int p1=0,p2=0,temp;
        while(p2<nums.length&&nums[p2]==0){
            p2++;
        }
        while(p2<nums.length&&p1<nums.length){
            if(nums[p1]==0){
                temp=nums[p1];
                nums[p1]=nums[p2];
                nums[p2]=temp;
            }
            p1++;
            while(p2<nums.length&&nums[p2]==0){
                p2++;
            }
        }
    }

    public int[] twoSum(int[] numbers, int target) {
        int left=0;
        int right=numbers.length-1;
        while(left<right){
            if(numbers[left]+numbers[right]<target){
                left++;
            }else if(numbers[left]+numbers[right]>target){
                right--;
            }else{
                return new int[]{left+1,right+1};
            }
        }
        return null;
    }
    
    public boolean isThree(int n) {
        int count=0;
        for(int i=1;i<=n;i++){
            if(n%i==0){
                count++;
            }
        }
        return count==n;
    }

    public long minimumPerimeter(long neededApples) {
        long n=0;
        long sum=0;
        while(sum<neededApples){
            n++;
            sum+=12*n*n;
        }
        return n*8;
    }

    @Test
    public void test(){
        System.out.println(minimumPerimeter(1000000000));
    }
}